import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import homework from '@/components/homework'
import register from '@/components/register'
import login from '@/components/login'
import myprofile from '@/components/myprofile'
import register2 from '@/components/register2'
import login2 from '@/components/login2'
import myprofile2 from '@/components/myprofile2'
import addgoods from '@/components/addgoods'
import editgood from '@/components/editgood'
import addgoods2 from '@/components/addgoods2'
import goodslist from '@/components/goodslist'
import exam4 from '@/components/exam4'



Vue.use(Router)

var routes = [{
        path: '/',
        name: 'index',
        component: index
    },
    {
        path: '/cart',
        name: 'cart',
        component: cart
    },
    {
        path: '/item',
        name: 'item',
        component: item
    },
    {
        path: '/detail',
        name: 'detail',
        component: detail
    },
    {
        path: '/mytest',
        name: 'mytest',
        component: mytest
    },
    {
        path: '/test',
        name: 'test',
        component: test
    },
    {
        path: '/homework',
        name: 'homework',
        component: homework
    },
    {
        path: '/register',
        name: 'register',
        component: register
    },
    {
        path: '/login',
        name: 'login',
        component: login
    },
    //拦截器的使用
    {
        path: '/myprofile',
        name: 'myprofile',
        component: myprofile,
        beforeEnter: (to, from, next) => {
            //判断用户是否登录
            if (localStorage.getItem('username')) {

                next()
            } else {

                next('/login')
            }
        }
    },
    {
        path: '/register2',
        name: 'register2',
        component: register2
    },
    {
        path: '/login2',
        name: 'login2',
        component: login2
    },
    {
        path: '/myprofile2',
        name: 'myprofile2',
        component: myprofile2
    },
    {
        path: '/addgoods',
        name: 'addgoods',
        component: addgoods
    },
    {
        path: '/editgood',
        name: 'editgood',
        component: editgood
    },
    {
        path: '/addgoods2',
        name: 'addgoods2',
        component: addgoods2
    },
    {
        path: '/goodslist',
        name: 'goodslist',
        component: goodslist
    },
    {
        path: '/exam4',
        name: 'exam4',
        component: exam4
    },
]

export default new Router({
    routes: routes,
    mode: 'history' /*hash*/
})